package com.pams.controller;

import cn.hutool.core.date.DateTime;
import com.pams.pojo.entity.Journal;
import com.pams.result.Result;
import com.pams.service.JournalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/api/journal")
public class JournalController {
    @Autowired
    private JournalService journalService;
    @PutMapping("/add")
    public Result<Integer>  add(@RequestBody  Journal journal){
       int id =  journalService.add(journal);
        return Result.success(id);
    }

    @GetMapping("/query")
    public Result<List<Journal>> getlist(){
        List<Journal> list = journalService.getlist();
        return Result.success(list);
    }

    @GetMapping("/")
    public Result<Journal> getSelectedJournal(@RequestParam int id ){
     Journal journal =   journalService.getSelectedJournal(id);
     return Result.success(journal);
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam int id){
        journalService.delete(id);
        return Result.success();
    }
    @GetMapping("/search")
    public Result<List<Journal>> search(@RequestParam String title){
        List<Journal> list = journalService.search(title);
        return Result.success(list);
    }


}
